<?
session_start();
require_once 'utils/user.php';
require_once 'utils/archive.php';
ManageUser::doLogin();

$error = new Messages();
if ($_SESSION['login']=='anonyme') {
    $error->pushMessage('You need log in to creat new article.', MSG_HEAD);
    Client::showUri('index.php');
}

$m = ManageArchive::doCreat();
if ($m) {
    if ($m->pollMessageByCode(604)) $error->pushMessage('Same title existed already.', MSG_HEAD);
    if ($m->pollMessageByCode(605)) $error->pushMessage('Null title!.', MSG_HEAD);
    if ($m->pollMessageByCode(606)) $error->pushMessage('Null content!', MSG_HEAD);
    $m1 = $m->pollMessageByCode(501);
    if ($m1) {echo $m1[0];SessionMsg::pushMessage('Thank your for your attribution!',MSG_HEAD);Client::showUri($m1[0]);}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/all.css"/>
        <style>
            /*error message*/
            #error_message {width:300px;margin:0px auto 3px auto;padding:4px;background: lightpink;border:1px solid chocolate;}
            form {width:300px;margin:0px auto;}
            form input[type="text"],form textarea {width:300px;padding:4px;}
        </style>
    </head>
    <body>
        <? if (SessionMsg::hasMessage()) foreach (SessionMsg::pollMessageByCode(MSG_HEAD) as $message) {echo $message;} ?>
    <? if ($error->hasMessage()) {?>
    <div id="error_message">Please check:
            <ul>
        <? foreach ($error->pollAllMessages() as $singleMessage) {
            echo "<li>".$singleMessage;
        }?>
            </ul>
        </div><? }?>
        <form action="creat.php?creat" method="post">
            Title:<br/><input type="text" name="title" value="<?=isset($_POST["title"])?$_POST["title"]:""?>"/><br/>
            Content:<br/><textarea cols="20" rows="20" name="content"><?=isset($_POST["content"])?$_POST["content"]:""?></textarea><br/>
            <input type="submit" name="submit" value="Creat my article"/>
        </form>
    </body>
</html>
